package com.taozi.minidao.example.test;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.junit.Before;
import org.junit.Test;


import com.taozi.minidao.example.dao.UserDao;
import com.taozi.minidao.example.entity.User;

public class UserDaoJunit extends SpringTxTestCase{
	
	@Resource(name="userDao")
	UserDao userDao;
	
	int maxCount;
	
	@Test
	public void getCount() {
		maxCount = userDao.getCount();
		logger.info("当前数据条数 --------------------------(" + maxCount + ")");
	}
	
//	@Test
	public void getAll() {
		User user = new User();
		user.setAge(18);
		List<Map<String, Object>> list = userDao.getAll(user);
		logger.info("--------------------------------------------------");
		for(Map m : list) {
			logger.info("id:" + m.get("id"));
			logger.info("name:" + m.get("name"));
			logger.info("age:" + m.get("age"));
			logger.info("birthday:" + m.get("birthday"));
			logger.info("address:" + m.get("address"));
			
		}
	}
	
//	@Test
	public void insert() {
		logger.info("--------insert--------------------------------------------------------------");
		User user = new User();
		String id = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
		user.setId(id);
		user.setName("桃子");
		user.setAge(18);
		user.setBirthday(new Date());
		user.setAddress("北京");
		userDao.insert(user);
	}
	
//	@Test
	public void update() {
		logger.info("--------update--------------------------------------------------------------");
		User user = new User();
		String id = "2949DA554C494A66B23DA53E7DCEF28C";
		user.setId(id);
		user.setName("桃子update");
		user.setAge(81);
		user.setAddress("四川");
		userDao.update(user);
	}
	
//	@Test
	public void delete() {
		logger.info("---------delete-----------------------------------------");
		String id = "2949DA554C494A66B23DA53E7DCEF28C";
		userDao.delete(id);
	}
	

}
